package com.longcai.piaojia.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/9/7.
 */
@HttpInlet(Conn.USERCOUPON_GET)
public class MineCouponListGet extends BaseAsyGet<MineCouponListGet.MineCouponListEntity> {

    public String user_id, type;

    public MineCouponListGet(AsyCallBack<MineCouponListEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected MineCouponListEntity parser(JSONObject object) throws Exception {
        
        TOAST = object.optString("message");
        
        if (object.optInt("code") == 200) {

            JSONArray array = object.optJSONArray("data");

            MineCouponListEntity mineCouponListEntity = new MineCouponListEntity();

            for (int i = 0; i < array.length(); i++) {

                JSONObject mineCouponObject = array.optJSONObject(i);

                MineCouponEntity mineCouponEntity = new MineCouponEntity();

                mineCouponEntity.id = mineCouponObject.optString("id");
                mineCouponEntity.user_id = mineCouponObject.optString("user_id");
                mineCouponEntity.title = mineCouponObject.optString("title");
                mineCouponEntity.money = mineCouponObject.optString("money");
                mineCouponEntity.total = mineCouponObject.optString("total");
                mineCouponEntity.starttime = mineCouponObject.optString("starttime");
                mineCouponEntity.endtime = mineCouponObject.optString("endtime");

                mineCouponListEntity.mineCouponList.add(mineCouponEntity);

            }
            
            return mineCouponListEntity;

        }

        return null;
    }

    public class MineCouponListEntity {

        public List<MineCouponEntity> mineCouponList = new ArrayList<>();
    }

    public class MineCouponEntity {

        public String id, user_id, title, money, total, starttime, endtime;

    }

}
